package cn.jinshengda.controller;


import cn.jinshengda.Dto.Daily;
import cn.jinshengda.entity.DailyPaper;
import cn.jinshengda.entity.MonthlyPaper;
import cn.jinshengda.service.MonthlyPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.text.SimpleDateFormat;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-01-08
 */
@RestController
@CrossOrigin
public class MonthlyPaperController {
    @Autowired
    private MonthlyPaperService monthlyPaperService;

    /*
     * @Author Lxy
     * @Description //TODO 添加月报
     * @Param  employeeId 员工id daily 添加的月份,应交实交份数
    */
    @PostMapping("monthly/add/{monthlyId}")
    public void addDailyPaper(@PathVariable("monthlyId") Integer employeeId, @RequestBody Daily daily){

        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM");
        String time = simpleDateFormat.format(daily.getMonth());

        MonthlyPaper monthlyPaper=new MonthlyPaper();
        monthlyPaper.setEmployeeId(employeeId);
        monthlyPaper.setCount(daily.getDue());
        monthlyPaper.setCounted(daily.getRealCross());
        monthlyPaper.setTime(time);
        monthlyPaperService.save(monthlyPaper);
    }
}

